package com.ks.controller;

import com.ks.common.PageResult;
import com.ks.common.Result;
import com.ks.dto.PageQueryDTO;
import com.ks.entity.Rule;
import com.ks.service.RuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/rule")
@Slf4j
public class RuleContronller {

    @Autowired
    private RuleService ruleService;

    //分页查询规则列表
    @PostMapping("/list")
    public Result<PageResult> list(@RequestBody PageQueryDTO pageQueryDTO) {
//        log.info("分页查询规则列表:{}", pageQueryDTO);
        PageResult pageResult = ruleService.pageRule(pageQueryDTO);
        return Result.success(pageResult);
    }


    //新增规则
    @PostMapping
    public Result add(@RequestBody Rule rule) {
        log.info("新增规则:{}", rule);
        ruleService.addRule(rule);
        return Result.success();
    }

    //修改规则
    @PutMapping
    public Result update(@RequestBody Rule rule) {
        log.info("修改规则:{}", rule);
        ruleService.updateRule(rule);
        return Result.success();
    }
    //删除规则
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        log.info("删除规则id:{}", id);
        ruleService.deleteRule(id);
        return Result.success();
    }


}
